package cn.iocoder.yudao.module.els.dal.mysql.codeGeneratorDetail;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.els.controller.admin.codeGeneratorDetail.vo.CodeGeneratorDetailPageReqVO;
import cn.iocoder.yudao.module.els.dal.dataobject.codeGeneratorDetail.CodeGeneratorDetailDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 编码生成器明细 Mapper
 *
 * @author 吕小文
 */
@Mapper
public interface CodeGeneratorDetailMapper extends BaseMapperX<CodeGeneratorDetailDO> {

    default PageResult<CodeGeneratorDetailDO> selectPage(CodeGeneratorDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CodeGeneratorDetailDO>()
                .eqIfPresent(CodeGeneratorDetailDO::getGeneratorId, reqVO.getGeneratorId())
                .eqIfPresent(CodeGeneratorDetailDO::getSeq, reqVO.getSeq())
                .eqIfPresent(CodeGeneratorDetailDO::getValueType, reqVO.getValueType())
                .likeIfPresent(CodeGeneratorDetailDO::getVariableName, reqVO.getVariableName())
                .eqIfPresent(CodeGeneratorDetailDO::getValue, reqVO.getValue())
                .eqIfPresent(CodeGeneratorDetailDO::getValueLength, reqVO.getValueLength())
                .eqIfPresent(CodeGeneratorDetailDO::getIsSerialKey, reqVO.getIsSerialKey())
                .betweenIfPresent(CodeGeneratorDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CodeGeneratorDetailDO::getId));
    }

    default List<CodeGeneratorDetailDO> selectListByGeneratorId(Long generatorId) {
        LambdaQueryWrapperX<CodeGeneratorDetailDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.eq(CodeGeneratorDetailDO::getGeneratorId,generatorId);
        queryWrapperX.orderByAsc(CodeGeneratorDetailDO::getSeq);
        return selectList(queryWrapperX);
    }

    default int deleteByGeneratorId(Long generatorId) {
        return delete(CodeGeneratorDetailDO::getGeneratorId, generatorId);
    }
}